<?php include incTemplate('header');?>
<link rel="stylesheet" href="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.css">
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/AjaxFileUploader/ajaxfileupload.js"></script>
<script type="text/javascript">
$(function(){

	$(".tbimg").hover(
	  function () {
	    $(this).css("background-color","#FBEC88");
	  },
	  function () {
		 $(this).css("background-color","");
	  }
	);
	
	$("a[rel=certimg]").fancybox();

	$("#addcert").click(function(){
	    $('#win_add').window({  
	        modal:true,
	        width:350,
	        height:180,
	        draggable:false,
	        minimizable:false,
	        maximizable:false,
	        collapsible:false
	    });  
	});
	
	$("#updatecert").click();

	$("#deletecert").click(function(){
		var carts = $("input:checkbox");
		var checked = false;
		var cartslist = new Array();
		carts.each(function(i){
			var ck = $(this).attr("checked");
			if(ck){
				checked = true;
				cartslist.push($(this).val());
			}
		});

		if(!checked){
			$.messager.alert('提示','请选择证书！'); 
		}else{
			$("#form1").attr("action","/admin.php/cert/deletecert");
			$("#certids").val(cartslist);
			$("#form1").submit();
		}
	});

	$("#btn_add").click(function(){
		var titleval = $("#title").val();
		var certimg = $("#certimg").val();

		if(certimg == ""){
			$.messager.alert('提示','上传图片不能为空！');
			return;
		}
		
		if(!isImg(certimg)){
			$.messager.alert('提示','上传的图片类型不正确！');
			return;
		}
		
		$.ajaxFileUpload
		(
			{
				url:'/admin.php/cert/addcert',
				secureuri:false,
				fileElementId:'certimg',
				dataType: 'json',
				data:{title:titleval},
				success: function (data, status)
				{
					if(data.success==true){
						$.messager.alert('提示','添加成功！');
					}else{
						$.messager.alert('提示','上传时有误！');
					}
				},
				error: function (data, status, e)
				{
					$.messager.alert('异常信息',e);
				}
			}
		)
		
	});


	
});
</script>
</head>
<body class="body" >

<div class="hidden">
<div id="win_add" title="添加证书">
<table class="tab_form" style="margin-top:20px;" >
	<tr>
		<td class="edit_td" width="80px">名称：</td><td class="rig_td">
		<input type="text" name="title" class="easyui-validatebox" required="true" id="title" class="w_200" />
		</td>
	</tr>
	<tr>
		<td class="edit_td">图片：</td><td class="rig_td">
		<input type="file" name="certimg" id="certimg" />
		</td>
	</tr>
	<tr>
		<td></td>
		<td><input id="btn_add" type="button" value="添加证书"/></td>
	</tr>
</table>
</div>
</div>



<form action="" method="post" id="form1">
<input type="hidden" name="certids" id="certids" />
<div style="padding:5px;background:#efefef;" class="mgb_10">
	<a class="easyui-linkbutton" plain="true" iconCls="icon-add" id="addcert">添加证书</a>
	<a class="easyui-linkbutton" plain="true" iconCls="icon-edit" id="updatecert">修改证书</a>
	<a class="easyui-linkbutton" plain="true" iconCls="icon-cut" id="deletecert">删除证书</a>
</div>

<table width="100%" >
	<?php 
	$i==0;
foreach ($certs as $cert){
	if($i==0){
		echo '<tr>';
	}
	
if($i%6==0&&$i!=0){
			echo '</tr></tr>';
						?>
			<td>
					<table class="tbimg" style="width:100%;">
					<tr>
						<td><?php echo $cert['title'];?></td>
					</tr>
					<tr> 
						<td valign="middle"><a class="certimg"  rel="certimg" href="/<?php echo $cert['location'];?>"><img  src="/<?php echo $cert['location'];?>"   height="100" max-width="100"  /></a></td>
					</tr>
					<tr>
						<td><?php echo $cert['createtime'];?></td>
					</tr>
					<tr>
						<td><input name="certids" type="checkbox" value="<?php echo $cert['id'];?>"/></td>
					</tr>
				</table>
				</td>
			<?php
		}else{
			?>
				<td>
					<table class="tbimg" style="width:100%;">
					<tr>
						<td><?php echo $cert['title'];?></td>
					</tr>
					<tr>
						<td valign="middle"><a  rel="certimg" href="/<?php echo $cert['location'];?>"><img src="/<?php echo $cert['location'];?>"  height="100"  /></a></td>
					</tr>
					<tr>
						<td><?php echo $cert['createtime'];?></td>
					</tr>
					<tr>
						<td><input name="certids" type="checkbox" value="<?php echo $cert['id'];?>"/></td>
					</tr>
				</table>
				</td>
			<?php 	
		}
	
	if($i==sizeof($certs)-1){
		$surplus = sizeof($certs)%6;
		if($surplus!=0){
			for($j=0;$j<(6-$surplus);$j++){
				echo '<td></td>';
			}
		}
		echo '</tr>';
	}
	$i++;
}
	?>
	

</table>
</form>
</body>
</html>